package com.emep.changzhi.analyse.service.datamonitor;

import com.emep.changzhi.analyse.entity.datamonitor.DataDroppedRecord;
import com.emep.changzhi.analyse.repository.datamonitor.DataDroppedRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

/**
 * @author yangj
 * @version V1.0
 * @Description: 掉线记录业务层
 * @date 2018/2/26  17:04
 */
@Slf4j
@Service
@Transactional
public class DataDroppedRecordService {


    @Autowired
    private DataDroppedRepository dataDroppedRepository;

    /**
     * 新增掉线记录，如果想修改，需要传一个id
     */
    public DataDroppedRecord saveDataDroppedRecord(Map<String , Object> payload){
        DataDroppedRecord dataDroppedRecord = null;
        try {
            dataDroppedRecord = (DataDroppedRecord) MapUtils.convertMap(DataDroppedRecord.class , payload);
        } catch (IntrospectionException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return dataDroppedRepository.save(dataDroppedRecord);
    }
    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 10:11
     * @version V1.0
     */
    public List<DataDroppedRecord> findDataDroppedRecordByHome(Integer pageSize){
        List<DataDroppedRecord> dataDroppedRecords = null;
        try {
            dataDroppedRecords = dataDroppedRepository.dataDroppedRecordHome(pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return dataDroppedRecords;

    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 10:18
     * @version V1.0
     */

    public List<DataDroppedRecord> findDataDroppedRecordByFlip(String id,Integer pageSize) {
        List<DataDroppedRecord> dataDroppedRecords = null;
        try {
            dataDroppedRecords = dataDroppedRepository.dataDroppedRecordFlip(id,pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return dataDroppedRecords;
    }


}
